<?php

class apidefinition_ControllerController extends Zend_Controller_Action
{
  function init() {
  	header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
	header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
    $this->getHelper('viewRenderer')->setNoRender();
  }

  function createAction() {
    require_once('apidefinition/objects/controller.php');
    try{
	  $results = APIDefinition_Object_Controller::create($this->_getAllParams());
    } catch(APIDefinition_Object_Exception $e) {
      $data['status'] = 	'KO';
      $data['error']['num'] = 	$e->getCode();
      $data['error']['message'] = 	$e->getMessage();
    echo Zend_Registry::get('dt_serializer')->serialize($data);	
      return;
    }
	$data['status'] = 	'OK';
    echo Zend_Registry::get('dt_serializer')->serialize($data);	
    return;
  }
  
  
  function getAction() {
    require_once('apidefinition/objects/controller.php');
    try {
      $controller = new APIDefinition_Object_Controller($this->_getParam('name'),$this->_getParam('moduleName'));
      $resController = $controller->asArray();
    } catch(APIDefinition_Object_Exception $e) {
      $data['status'] = 	'KO';
      $data['error']['num'] = 	$e->getCode();
      $data['error']['message'] = 	$e->getMessage();
    echo Zend_Registry::get('dt_serializer')->serialize($data);	
      return;
    }
    
    //We list the different actions of the controller
    require_once('apidefinition/objects/action.php');
    $resActions = APIDefinition_Object_Action::listing($controller->getName(),$resController['moduleName']);
    
    
	$data['status'] = 	'OK';
	$data['controller'] = $resController;
	$data['actions'] = $resActions;
    echo Zend_Registry::get('dt_serializer')->serialize($data);	
    return;  	
  }

} //End class


?>